<template>
  <div>
    <van-address-edit
      :area-list="areaList"
      :address-info="addressinfo"
      show-postal
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import { areaList } from "@vant/area-data";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addressinfo: {
        name: "",
        tel: "",
        province: "",
        city: "",
        county: "",
        addressDetail: "",
        postalCode: "",
        isDefault: "",
      },
    };
  },
  methods: {
    onSave(content) {
      this.addressinfo = content;
      let str = {
        tel: content.tel,
        receiver: content.name,
        regions: content.province + content.city + content.county,
        addres: content.addressDetail,
      };

      localStorage.setItem("address", JSON.stringify(str));
      this.$store.commit("address/savereceiver", str);
      this.$router.go(-1);
    },
    onDelete() {
      Toast("delete");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
          {
            name: "千锋教育",
            address: "郑州市高新区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },
};
</script>

<style scoped></style>
